﻿#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      Particulier
#
# Created:     18/10/2011
# Copyright:   (c) Particulier 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python

# lecture du fichier Ui_Mainform.py

from csv import reader





print "import sys"
print "from PyQt4 import QtGui, QtCore"
print "from Ui_MainForm import Ui_MainWindow"
print ""
print "class MonAppli(QtGui.QMainWindow, Ui_MainWindow):"
print "    def __init__(self):"
print "        QtGui.QMainWindow.__init__(self)"
print "        Ui_MainWindow.__init__(self)"
print ""
print "        # Configure l'interface utilisateur."
print "        self.setupUi(self)"



nomfic="Ui_MainForm.py"
fic = reader(open(nomfic,'r'))
#
M=[] # menu
B=[] # bouton
L=[] # lineedit
# recherche chaine QAction  pour detecter les menus
for row in fic:
    s=str(row)
    ind=s.find('QAction')
    i0=s.find('.')
    i1=s.find('=')

    if ind >0:
        l= s[i0+1:i1-1]
        M.append(l)
#recherche QPushButton
fic = reader(open(nomfic,'r'))
for row in fic:
    s=str(row)
    ind=s.find('QPushButton')
    i0=s.find('.')
    i1=s.find('=')

    if ind >0:
        l= s[i0+1:i1-1]
        B.append(l)
# recherche lineEdit QLineEdit
print " "
fic = reader(open(nomfic,'r'))
for row in fic:
    s=str(row)
    ind=s.find('QLineEdit')
    i0=s.find('.')
    i1=s.find('=')

    if ind >0:
        l= s[i0+1:i1-1]
        L.append(l)

print "  "
print "#--------------------------------------------------------------------"
print "# menus"
print "#--------------------------------------------------------------------"
for i in range(len(M)):
        smenu="        self.connect(self."+M[i]+",QtCore.SIGNAL(\"triggered()\"),On_"+M[i]+")"
        print smenu
print "  "
print "#--------------------------------------------------------------------"
print "# boutons"
print "#--------------------------------------------------------------------"
for i in range(len(B)):
        sbouton="        self.connect(self."+B[i]+",QtCore.SIGNAL(\"clicked()\"),On_"+B[i]+")"
        print sbouton
print "  "

print "  "
print "#--------------------------------------------------------------------"
print "# lineEdit"
print "#--------------------------------------------------------------------"
for i in range(len(L)):
        slineEdit="        self.connect(self."+L[i]+",QtCore.SIGNAL(\"returnPressed()\"),On_"+L[i]+")"
        print slineEdit
print "#--------------------------------------------------------------------"
print "# fonctions des menus "
print "#--------------------------------------------------------------------"
for i in range(len(M)):
    print "def On_"+M[i]+"():"
    print "    print "+"\""+M[i]+"\""
    print "    pass"
    print "    return"
    print "  "
print "#--------------------------------------------------------------------"
print "# fonctions des boutons   "
print "#--------------------------------------------------------------------"
for i in range(len(B)):
    print "def On_"+B[i]+"():"
    print "    print "+"\""+B[i]+"\""
    print "    pass"
    print "    return"
    print "  "
print "#--------------------------------------------------------------------"
print "# fonctions des LineEdit    "
print "#--------------------------------------------------------------------"
for i in range(len(L)):
    print "def On_"+L[i]+"():"
    print "    \" get w."+L[i]+".text()  faire la conversion vers int ou float\""
    print "    print "+"\""+L[i]+"\""
    print "    pass"
    print "    return"
    print "  "

print "if __name__ == ""\"""__main__""\""":"
print "    app = QtGui.QApplication(sys.argv)"
print "    window = MonAppli()"
print ""
print "    window.show()"
print "    sys.exit(app.exec_())"